home *** CD-ROM | disk | FTP | other *** search
- Path: uu4news.netcom.com!otsrvr!Ray_Robert
- From: Ray_Robert@ortel.org (Ray Robert)
- Reply-To: Ray_Robert@ortel.org
- Newsgroups: comp.lang.c
- Distribution: world
- Subject: Re: A problem with fprintf
- Date: 09 Jan 1996 07:36:35 GMT
- Message-ID: <2154942365.28352469@ortel.org>
- Organization: Oregon Telcom
-
- vishwajit@cis.ufl.edu writes:
-
- > I am experiencing a peculiar problem with fprintf.
-
- > I have a piece of code where the following statement fits in:
-
- fprintf(fp, "%s\n", src);
- >
- >fp is a file-pointer and src is a static array of characters. When the
- > code is executed repeatedly, it fails at the above statement. The error
- > message from the debugger is as follows:
-
- > signal SEGV (segmentation violation) in malloc at 0xef778634
- > malloc+0x150: st %o0, [%l5]
-
- > fp is pointing to a file that has been opened and is not the problem.
- > Does somebody have a clue?
-
- Apparently your system's fprintf is doing an malloc() to set up a space in
- which to construct the formatted string (wow! what an inefficiency there).
- It is probably incorrectly determining the size of "src", which it expects to
- be a (pointer to a) null-terminated string. One of 2 things is happening (I
- leave it to the academics out there to tell us which is ANSI C):
-
- (1) The array is being passed by value, i.e., the literal value of the first
- element is being passed to fprintf and hence to malloc, but it's being
- interpretted as if it's a pointer.
-
- (2) The last element of the array is not a null ('\0' in the old style, 0 in
- the new).
-
- Ray Robert
-